<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/11
  Time: 19:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>图书系统首页</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery-3.6.0.js"></script>
</head>
<body style="background-color: rgba(174,174,174,0.55)">
<div class="page-header">
    <h1>图书管理界面</h1>
    网站当前登陆人数：${count}
</div>

    <table class="table table-striped">
        <thead>
        <tr>
            <th>id</th>
            <th>图书名称</th>
            <th>作者</th>
            <th>出版社</th>
            <th>出版时间</th>
            <th>是否被借阅</th>
        </tr>
        </thead>

        <tbody id="tbody">

        </tbody>
    </table>

<a href="/returnBooks.jsp" class="btn btn-primary btn-lg active" role="button">自己借阅的图书</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="/borrowBooks.jsp" class="btn btn-primary btn-lg active" role="button">未被借阅的图书</a>&nbsp;&nbsp;&nbsp;&nbsp;
<br>
<br>
<br>
<a href="/logout.do" class="btn btn-default btn-lg active" role="button">退出登录</a>

</body>
</html>
<script>

    $(function () {
        //获取页面初始化值
        getData();
    });

    function getData() {
        //获取页面初始化值
        $.getJSON("bookSystem.do",{flag:"init"},function (result) {
            init(result);
        })
    }

    function init(data) {
        console.log(data);
        var data_length = data.length;
        for (var i = 0;i<data_length;i++){
            if (data[i].readId!=0){
                $("#tbody").append("<tr>" +
                    "<td>" +data[i].bookId+"</td>"+
                    "<td>" +data[i].bookName+"</td>"+
                    "<td>" +data[i].author+"</td>"+
                    "<td>" +data[i].publisher+"</td>"+
                    "<td>" +data[i].pubDate+"</td>"+
                    "<td>有人</td></tr>"
                )
            }else {
                $("#tbody").append("<tr>" +
                    "<td>" +data[i].bookId+"</td>"+
                    "<td>" +data[i].bookName+"</td>"+
                    "<td>" +data[i].author+"</td>"+
                    "<td>" +data[i].publisher+"</td>"+
                    "<td>" +data[i].pubDate+"</td>"+
                    "<td>无</td></tr>")
            }
        }
    }
</script>

